#include <stdio.h>
#include <stdlib.h>
#define bool unsigned int
#define true 1
#define false 0
#define none 2

bool MatchCore(char* str, char* pattern)
{
	if (*str == '\0' && *pattern == '\0')
		return true;
	if (*str != '\0' && *pattern == '\0')
		return false;
	if (*(pattern + 1) == '*')
	{
		if (*(pattern + 2) == '*')return false;
		if (*str == *pattern || *str != '\0' && *pattern == '.')
		{
			return MatchCore(str + 1, pattern) || MatchCore(str + 1, pattern + 2) || MatchCore(str, pattern + 2);
		}
		else
			return MatchCore(str, pattern + 2);
	}
	else
	{
		if (*str == *pattern || *str != '\0' && *pattern == '.')
			return MatchCore(str + 1, pattern + 1);
		else
			return false;
	}
}

bool Match(char* str, char* pattern)
{
	if (str == NULL || pattern == NULL)
		return false;
	if (*pattern == '*')
		return false;
	MatchCore(str, pattern);
}
void main()
{
	char* str = "aaa";
	char* pattern = "ab*a*c*a";
	bool state = Match(str, pattern);
	if (state)printf("YES");
	else printf("NO");
}
